home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / mint / lib / mntlib44.zoo / mntlib / ftell.c < prev    next >
C/C++ Source or Header  |  1994-03-01  |  616b  |  37 lines

  1. /* something like the origonal
  2.  * from Dale Schumacher's dLibs
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <unistd.h>
  7.  
  8. long
  9. ftell(fp)
  10.   FILE *fp;
  11. {
  12.   long rv, count = fp->_cnt, adjust = 0;
  13.   unsigned int f = fp->_flag;
  14.  
  15.   if (((f & _IOREAD) && (!(f & _IOBIN)))
  16.       || (count == 0)
  17.       || (f & _IONBF))
  18.   {
  19.     fflush(fp);    
  20.     rv = lseek(fp->_file, 0L, SEEK_CUR);
  21.   }
  22.   else
  23.   {
  24.     if (f & _IOREAD)
  25.       adjust = -count;
  26.     else if (f & (_IOWRT | _IORW))
  27.     {
  28.       if(f & _IOWRT)
  29.         adjust = count;
  30.     }
  31.     else return -1L;
  32.  
  33.     rv = lseek(fp->_file, 0L, SEEK_CUR);
  34.   }
  35.   return (rv < 0) ? -1L : rv + adjust;
  36. }
  37.